package cn.cubix.flow.controller.dto.workflow;

import lombok.Data;
import lombok.experimental.Accessors;
import org.flowable.engine.runtime.ProcessInstance;

import java.util.Date;
import java.util.Map;

@Data
@Accessors(chain = true)
public class ProcessInstDto {
    protected String processInstanceId;
    protected String processDefinitionId;
    protected String processDefinitionName;
    protected String processDefinitionKey;
    protected Integer processDefinitionVersion;
    protected String deploymentId;
    protected String businessKey;
    protected Boolean suspended;
    protected Map<String, Object> processVariables;
    protected String tenantId;
    protected String id;
    protected String name;
    protected String description;
    protected String localizedName;
    protected String localizedDescription;
    protected Date startTime;
    protected String startUserId;
    protected String callbackId;
    protected String callbackType;
    protected String activityId;
    protected Boolean ended;
    protected String parentId;
    protected String superExecutionId;
    protected String rootProcessInstanceId;
    protected String referenceId;
    protected String referenceType;
    protected String propagatedStageInstanceId;

    public static ProcessInstDto from(ProcessInstance processInstance){
        return new ProcessInstDto()
                .setProcessInstanceId(processInstance.getProcessInstanceId())
                .setProcessDefinitionId(processInstance.getProcessDefinitionId())
                .setProcessDefinitionName(processInstance.getProcessDefinitionName())
                .setProcessDefinitionKey(processInstance.getProcessDefinitionKey())
                .setProcessDefinitionVersion(processInstance.getProcessDefinitionVersion())
                .setDeploymentId(processInstance.getDeploymentId())
                .setBusinessKey(processInstance.getBusinessKey())
                .setSuspended(processInstance.isSuspended())
                .setProcessVariables(processInstance.getProcessVariables())
                .setTenantId(processInstance.getTenantId())
                .setId(processInstance.getId())
                .setName(processInstance.getName())
                .setDescription(processInstance.getDescription())
                .setLocalizedName(processInstance.getLocalizedName())
                .setLocalizedDescription(processInstance.getLocalizedDescription())
                .setStartTime(processInstance.getStartTime())
                .setStartUserId(processInstance.getStartUserId())
                .setCallbackId(processInstance.getCallbackId())
                .setCallbackType(processInstance.getCallbackType())
                .setEnded(processInstance.isEnded())
                .setActivityId(processInstance.getActivityId())
                .setParentId(processInstance.getParentId())
                .setSuperExecutionId(processInstance.getSuperExecutionId())
                .setRootProcessInstanceId(processInstance.getRootProcessInstanceId())
                .setReferenceId(processInstance.getReferenceId())
                .setReferenceType(processInstance.getReferenceType())
                .setPropagatedStageInstanceId(processInstance.getPropagatedStageInstanceId())
                ;

    }
}
